﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XT.Model;
using XT.Repository;

namespace XT.BusinessService
{
    

    public class DistrictService : IDistrictService
    {
        private readonly IUow _uow;
        public DistrictService(IUow uow)
        {
            _uow = uow;
        }
        
        public IEnumerable<District> GetDistricts()
        {
            return _uow.DistrictRepo.FindAll<District>(o => o.OrderByDescending(c => c.Id));
        }



        public District GetDistrictByID(int id)
        {
            return _uow.DistrictRepo.Find(id);
        }

        public District searchDistrictByName(string txt)
        {
            return _uow.DistrictRepo.ExecuteQuery(context => context.GetTable<District>().SingleOrDefault(c => c.District_Name.Equals(txt)));
        }
        public IEnumerable<District> SuggestDistricts(string txt)
        {
            return _uow.AreaRepo.FindAllByCriteria<District>((c => c.District_Name.ToLower().Contains(txt.ToLower())), o => o.OrderByDescending(c => c.Id));
        }
    }
}
